﻿#pragma once

#include "World/Block.h"

// std
#include <unordered_set>

class Persistence;

class CORE_API BlockRegistry
{
public:
  BlockRegistry();

  void RegisterBlock(const Block &block);
  Block *GetBlock(Block::ID id);
  Block *GetBlock(const std::string &name);
  Block::ID GetBlockID(const std::string &name);
  bool IsBlockRegistered(const std::string &name) { return m_blockNames.contains(name); }
  
  const std::unordered_map<std::string, Block::ID> &GetAll() { return m_blockNameToID; }

  int GetBlockCount() const { return m_blocks.size(); }

  void RegisterDefaultBlocks();

private:
  std::vector<Block> m_blocks;

  // 方块名到ID的映射，会存储到存档中，无法判断方块名是否被注册
  std::unordered_map<std::string, Block::ID> m_blockNameToID;

  std::unordered_set<std::string> m_blockNames;

  friend class Persistence;
};